//
//  FeatureCollectionViewCell.m
//  UGoods
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 蓝鸥科技.李贺. All rights reserved.
//

#import "FeatureCollectionViewCell.h"
#import "FindModel.h"
#import "BaseLabel.h"
#import <UIImageView+WebCache.h>
#import "ConstantsDefine.h"
@interface FeatureCollectionViewCell ()

@property (nonatomic, retain) UIImageView *goodsImageView;
@property (nonatomic, retain) BaseLabel *goodsNameLabel;
@property (nonatomic, retain) BaseLabel *priceLabel;


@end

@implementation FeatureCollectionViewCell

- (void)dealloc
{
    [_goodsImageView release];
    [_goodsNameLabel release];
    [_priceLabel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.goodsImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_goodsImageView];
        [_goodsNameLabel release];
        
        self.goodsNameLabel = [[BaseLabel alloc] init];
        //        _goodsNameLabel.textAlignment = NSTextAlignmentCenter;
        //        _goodsNameLabel.backgroundColor = [UIColor redColor];
        _goodsNameLabel.numberOfLines = 2;
        _goodsNameLabel.textAlignment = NSTextAlignmentLeft;
        _goodsNameLabel.font = [UIFont systemFontOfSize:15 * WIDTH];
        [self.contentView addSubview:_goodsNameLabel];
        [_goodsNameLabel release];
        
        self.priceLabel = [[BaseLabel alloc] init];
        //        _priceLabel.backgroundColor = [UIColor yellowColor];
        _priceLabel.textAlignment = NSTextAlignmentLeft;
        _priceLabel.font = [UIFont systemFontOfSize:14 * WIDTH];
        _priceLabel.textColor = [UIColor redColor];
        [self.contentView addSubview:_priceLabel];
        [_priceLabel release];

    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    self.goodsImageView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, 160 * HEIGHT);
    self.goodsNameLabel.frame = CGRectMake(10 * WIDTH, 170 * HEIGHT, self.contentView.frame.size.width - 20 * WIDTH, 40 * HEIGHT);
    self.priceLabel.frame = CGRectMake(10 * WIDTH, 220 * HEIGHT, self.contentView.frame.size.width / 2, 20 * HEIGHT);

}

- (void)setModel:(FindModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [_goodsImageView sd_setImageWithURL:[NSURL URLWithString:model.goods_thumbnail] placeholderImage:[UIImage imageNamed:@"place2"]];
    _goodsNameLabel.text = model.goods_name;
    _priceLabel.text = [NSString stringWithFormat:@"¥%@", [model.goods_price stringValue]];

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
